(function(window) {
	var wechat = new Object();
	wechat.auth = function(callback) {
		request(callback);
	};
	function request(callback) {
		var params = {};
		params.url = window.location.href;
		$.ajax({
			url : "wx/getJsApiConfig",
			type : 'get',
			dataType : 'json',
			data : params,
			success : function(result) {
				var status = result.status;
				if (status == "success") {
					var data = result.data;
					wxConfig(data, callback);
				}
			},
			error : function(data) {
			}
		});
	}
	function wxConfig(body, callback) {
		var jsApiList = [ 'checkJsApi', 'onMenuShareTimeline',
				'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo',
				'onMenuShareQZone', 'hideMenuItems', 'showMenuItems',
				'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem',
				'translateVoice', 'startRecord', 'stopRecord', 'onRecordEnd',
				'playVoice', 'pauseVoice', 'stopVoice', 'uploadVoice',
				'downloadVoice', 'chooseImage', 'previewImage', 'uploadImage',
				'downloadImage', 'getNetworkType', 'openLocation',
				'getLocation', 'hideOptionMenu', 'showOptionMenu',
				'closeWindow', 'scanQRCode', 'chooseWXPay',
				'openProductSpecificView', 'addCard', 'chooseCard', 'openCard' ];
		wx.config({
			debug : false,
			appId : body.appId,
			timestamp : body.timestamp,
			nonceStr : body.nonceStr,
			signature : body.signature,
			jsApiList : jsApiList
		});
		wx.ready(function() {
			wx.checkJsApi({
				jsApiList : jsApiList,
				success : function(res) {
					callback&&callback();
				}
			});
		});
		wx.error(function(res) {
		});
	}
	;
	window.wechat = wechat;
})(window);